package com.lwei.tallybook.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lwei.tallybook.base.domain.rel.RelBookAccount;
import com.lwei.tallybook.service.mapper.rel.RelBookParticipatorMapper;
import com.lwei.tallybook.service.service.RelBookAccountService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class RelBookAccountServiceImpl extends ServiceImpl<RelBookParticipatorMapper, RelBookAccount> implements RelBookAccountService {

    @Override
    public List<RelBookAccount> listRelByBookUuid(String bookUuid) {
        QueryWrapper<RelBookAccount> wrapper = new QueryWrapper<>();
        wrapper.eq("consume_uuid", bookUuid);
        return super.list(wrapper);
    }

    @Override
    public List<RelBookAccount> listRelInBookUuid(List<String> bookUuids) {
        QueryWrapper<RelBookAccount> wrapper = new QueryWrapper<>();
        wrapper.in("consume_uuid", bookUuids);
        return super.list(wrapper);
    }

    @Override
    public List<RelBookAccount> listRelByAccountUuid(String accountUuid) {
        QueryWrapper<RelBookAccount> wrapper = new QueryWrapper<>();
        wrapper.eq("account_uuid", accountUuid);
        return super.list(wrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removeByBook(List<String> bookUuid) {
        QueryWrapper<RelBookAccount> wrapper = new QueryWrapper<>();
        wrapper.in("consume_uuid", bookUuid);
        super.remove(wrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removeByAccount(List<String> accountUuid) {
        QueryWrapper<RelBookAccount> wrapper = new QueryWrapper<>();
        wrapper.in("account_uuid", accountUuid);
        super.remove(wrapper);
    }
}
